#ifndef __BUOLA_GUI_CICON_H__
#define __BUOLA_GUI_CICON_H__

#include <buola/gui/ciconbase.h>
#include <unordered_map>
#include <buola/algorithm/hash.h>
#include <buola/image/cpicture.h>

namespace buola { namespace gui {

///\addtogroup gui
///@{

//! \name some standard icon names
//@{
#define ICON_STOCK_UP                   "go-up"
#define ICON_STOCK_PREVIOUS             "go-previous"
#define ICON_STOCK_NEXT                 "go-next"
#define ICON_STOCK_ARROW_RIGHT_DOUBLE   "arrow-right-double"
#define ICON_STOCK_ARROW_RIGHT          "arrow-right"
#define ICON_STOCK_HOME                 "go-home"
#define ICON_STOCK_LAST                 "go-last"
#define ICON_STOCK_FIRST                "go-first"
#define ICON_STOCK_DOC_NEW              "document-new"
#define ICON_STOCK_OPEN                 "document-open"
#define ICON_STOCK_SAVE                 "document-save"
#define ICON_STOCK_SAVE_AS              "document-save-as"
#define ICON_STOCK_EDIT                 "stock_edit"
#define ICON_STOCK_CONNECT              "stock_connect"
#define ICON_STOCK_EXPORT               "stock_export"
#define ICON_STOCK_PRINT                "stock_print"
#define ICON_STOCK_PREFERENCES          "preferences-desktop"
#define ICON_STOCK_EXIT                 "application-exit"
#define ICON_STOCK_HELP                 "stock_help"
#define ICON_STOCK_REFRESH              "view-refresh"
#define ICON_STOCK_RUN                  "system-run"
#define ICON_STOCK_INFO                 "dialog-information"
#define ICON_STOCK_OK                   "dialog-ok"
#define ICON_STOCK_CANCEL               "dialog-cancel"
#define ICON_STOCK_ERROR                "dialog-error"
#define ICON_STOCK_WARNING              "dialog-warning"
#define ICON_STOCK_UNDO                 "edit-undo"
#define ICON_STOCK_REDO                 "edit-redo"
#define ICON_STOCK_CLOSE                "stock_close"
#define ICON_STOCK_FOLDER_NEW           "folder-new"
//@}

////////////////////////////////////////////////////////////////////////////

/// icon-theme based icon

/// This specialization of CIconBase allows loading icons by name
///
////////////////////////////////////////////////////////////////////////////

class CIcon : public CIconBase
{
protected:
//! \name constructor and destructor
//@{
    CIcon();
    virtual ~CIcon();
//@}

    //! initializes the icon
    bool Init(const std::string &pName);

protected:
    //! loads a version of the icon
    virtual bool Load(int pSize,EStyle pStyle);

    //! gets a copy of the icon as a img::CPicture
    virtual img::CPicture GetNewPixmap(int pSize);

public:
    virtual bool Draw(img::CGC*,const CPoint_d&,int pSize,EStyle pStyle=NORMAL);
    virtual img::CPicture GetPixmap(int pSize,EStyle pStyle=NORMAL);

public:
    //! get an icon by its name
    static PIcon Get(const std::string &pName);

protected:
    std::string mName;     //!< icon name

    //! images for all versions
    std::unordered_map<std::pair<int,int>,img::CPicture,APairHash> mPixmaps;

private:
    //! map of all icons
    static std::unordered_map<std::string,PIcon> mIcons;

    //! mutex for loading icons
    static mutex mStaticMutex;
};

///@}

/*namespace gui*/ } /*namespace buola*/ }

#endif
